Climate change#
Student names: Thierry Schneider, Mark Kuster, Thomas Andersen, Jens Breusers
Team number: N7
Show code cell source
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
# POPULATION GR
file_path_new = r"Population_dataset.csv"
df_new = pd.read_csv(file_path_new, skiprows=4)
# TEMP VERHOGING
file_path = r"GlobalLandTemperaturesByCountry.csv"
df = pd.read_csv(file_path)
# 3D VIS
co2_emissions = pd.read_csv(r'CO2 emission by countries.csv', encoding='ISO-8859-1')
Environment_temp_dataset = pd.read_csv(r'Environment_Temperature_change_E_All_Data_NOFLAG_CSV.csv', encoding='ISO-8859-1')
temperature_change = Environment_temp_dataset
population_data = pd.read_csv(r'Population_dataset.csv', skiprows=4, delimiter=',', encoding='ISO-8859-1')
# ENERGY CONSUMPTION VS POPULATION
df_energy = pd.read_csv(r'energy_CSV.csv')
# ENERGY UNIT CONSUPTION
energy_data = pd.read_csv(r'energy_CSV.csv')
Show code cell source
#Load image from link
url = r"https://auramag.in/wp-content/uploads/2022/05/Climate-Change-Threat-or-Opportunity-@aura-emagazine.jpg"
# Display image from URL with smaller size and subtitle
from IPython.display import Image, display
# Set the desired image width and height
width = 600
height = 300
# Set the subtitle text
subtitle = "© Zakariya Khan"
# Create an Image instance with the URL
image = Image(url=url, width=width, height=height)
# Display the image and subtitle
display(image)
print(subtitle)

© Zakariya Khan
Introduction#
For four decades, the world has grappled with the dual challenges of population growth and increasing carbon dioxide (CO2) emissions. As the global population surged between 1980 and 2020, so did the demand for energy, resulting in heightened CO2 emissions and subsequent temperature changes. This story explores two perspectives on the relationship between population growth, energy consumption, and CO2 emissions. The first perspective highlights how population growth has driven up CO2 emissions, contributing to global temperature rise. The second perspective argues that high CO2 emissions are a necessary byproduct of meeting the world’s growing energy needs.
Using datasets sourced from Kaggle, we analyze the interplay between these factors over the past four decades. Through a series of data visualizations, we aim to portray the data clearly and engagingly, helping to raise public awareness about the critical issue of climate change.
By examining data from countries around the globe, including significant emitters like China and the United States, we provide a comprehensive view of how population growth and energy consumption patterns have influenced CO2 emissions and climate change. Our goal is to educate the public and provide insights into one of the most pressing issues of our time, fostering a deeper understanding of the challenges and potential paths forward in addressing climate change.
Dataset and preprocessing#
Population Growth (Population_dataset.csv):
This dataset contains information on population growth rates over time for various countries or regions. allowing analysis of trends in population growth globally or by specific regions.
Temperature Increase (GlobalLandTemperaturesByCountry.csv):
This dataset includes historical records of land surface temperatures by countries over a long period, from the 19th century to recent years. It provides insights into how temperatures have changed over time and how these changes vary across different parts of the world.
CO2 Emissions by Country (CO2 emission by countries.csv):
This dataset contains data on carbon dioxide (CO2) emissions from various countries. It includes monthly measurements of CO2 emissions, in metric tons.
Global Environmental Temperature Change (Environment_Temperature_change_E_All_Data_NOFLAG_CSV.csv):
This dataset provides comprehensive data on global environmental temperature changes over time.
Energy Consumption vs. Population (energy_CSV.csv):
This dataset contains information on energy consumption patterns across different countries or regions, broken down by type of energy source (e.g., fossil fuels, natural gas, etc). It would also likely include data on population growth rates over the same period, enabling analysis of the relationship between population dynamics and energy consumption trends.
we stripped some of the datasets of missing data and merged some when needed.
Each of these datasets plays a crucial role in understanding different aspects of climate change, including its drivers (population growth, energy consumption), impacts (temperature increases), and associated environmental effects (CO2 emissions). Analyzing these datasets provided insights into the complex interactions between human activities and the environment, helping to inform policies and strategies for sustainable development and climate action.
Population growth#
One of the key factors driving climate change is the rapid increase in global population. The past four decades have witnessed unprecedented population growth, particularly in certain countries. When we analyzed our dataset, we found that the top 5 most populous countries—China, India, the United States, Indonesia, and Brazil—have seen their combined populations grow from about 2 billion in 1980 to approximately 3.5 billion in 2020.
To illustrate this significant growth, we created a visualization showing the population trends in these countries over the last 40 years:
# POPULATION GROWTH FIG
top_countries_list = ['China', 'India', 'United States', 'Indonesia', 'Brazil']
years = [str(year) for year in range(1960, 2023)]
df_new[years] = df_new[years].apply(pd.to_numeric, errors='coerce')
df_filtered = df_new[df_new['Country Name'].isin(top_countries_list)]
df_melted = df_filtered.melt(id_vars=['Country Name', 'Country Code', 'Indicator Name', 'Indicator Code'],
value_vars=years,
var_name='Year',
value_name='Population')
df_melted['Year'] = pd.to_numeric(df_melted['Year'])
df_melted['Population'] = pd.to_numeric(df_melted['Population'])
df_melted = df_melted[(df_melted['Year'] >= 1980) & (df_melted['Year'] <= 2020)]
top_countries_list_sorted = ['China', 'India', 'United States', 'Indonesia', 'Brazil']
df_melted['Country Name'] = pd.Categorical(df_melted['Country Name'], categories=top_countries_list_sorted, ordered=True)
df_melted = df_melted.sort_values(by=['Year', 'Country Name'], ascending=[True, True])
fig = px.area(df_melted, x='Year', y='Population', color='Country Name',
title="Population Growth from 1980 to 2020 for the Top 5 Most Populous Countries",
labels={'Year': "Year", 'Population': "Population"})
fig.update_layout(
xaxis=dict(
range=[1980, 2020],
dtick=2,
tick0=1980,
rangeslider=dict(visible=True),
type="linear"
),
legend=dict(traceorder='reversed'),
updatemenus=[
dict(
buttons=list([
dict(
args=["xaxis.range", [1980, 1990]],
label="1980-1990",
method="relayout"
),
dict(
args=["xaxis.range", [1990, 2000]],
label="1990-2000",
method="relayout"
),
dict(
args=["xaxis.range", [2000, 2010]],
label="2000-2010",
method="relayout"
),
dict(
args=["xaxis.range", [2010, 2020]],
label="2010-2020",
method="relayout"
),
dict(
args=["xaxis.range", [1980, 2020]],
label="Full View",
method="relayout"
)
]),
direction="down",
showactive=True
)
]
)
# Show the plot
fig.show()
As the visualization demonstrates, China and India have experienced the most substantial population increases, contributing heavily to the global population surge. These two countries alone account for a significant portion of the world’s population growth. Meanwhile, the United States, Indonesia, and Brazil have also shown notable increases, further adding to the global trend.
This rapid population growth presents various challenges and implications. With more people comes a greater demand for resources, including food, water, and energy. The strain on these resources can lead to environmental degradation and increased greenhouse gas emissions, as more energy production typically means more CO2 emissions.
The next part of our analysis will delve deeper into how this population growth correlates with energy consumption and CO2 emissions.
Growing CO2 emissions#
Having established the rapid population growth over the past decades, it is important to explore how this growth correlates with CO2 emissions on a global scale. As the world’s population expands, the demand for energy increases, often resulting in higher CO2 emissions. To visualize this relationship, we created a 3D interactive graph that plots global population growth against CO2 emissions from 1980 to 2020. The color of the data points represents temperature differences over the years, providing an additional layer of context:
# 3D VIS
# Reshape the new population data from wide to long format
population_data = population_data.melt(id_vars=['Country Name', 'Country Code', 'Indicator Name', 'Indicator Code'],
var_name='Year', value_name='Population')
# Remove any non-numeric 'Year' entries
population_data = population_data[population_data['Year'].str.isnumeric()]
population_data['Year'] = population_data['Year'].astype(int)
population_data = population_data.dropna(subset=['Population'])
# Convert population from billions to millions
population_data['Population'] *= 1000
# Filter relevant years
population_data = population_data[population_data['Year'].between(1979, 2020)]
co2_emissions = co2_emissions[co2_emissions['Year'].between(1979, 2020)]
# Process the population data
population_data = population_data.groupby(['Country Name', 'Year'])['Population'].sum().reset_index()
population_data.rename(columns={'Country Name': 'Country'}, inplace=True)
# Process the CO2 emissions data
co2_emissions.rename(columns={'CO2 emission (Tons)': 'CO2 Emissions'}, inplace=True)
co2_emissions['CO2 Growth'] = co2_emissions.groupby('Country')['CO2 Emissions'].diff().fillna(0)
# Calculate global values
global_population = population_data.groupby('Year')['Population'].sum().reset_index()
global_population['Country'] = 'World'
global_co2 = co2_emissions.groupby('Year')['CO2 Growth'].sum().reset_index()
global_co2['Country'] = 'World'
# Combine global data
global_data = pd.merge(global_population, global_co2, on='Year')
# Process the temperature change data
# Reshape temperature data from wide to long format
temperature_change = temperature_change.melt(id_vars=['Area', 'Element'], var_name='Year', value_name='Temperature')
temperature_change['Year'] = temperature_change['Year'].str.extract('(\d+)', expand=False).astype(float)
temperature_change = temperature_change.dropna(subset=['Year', 'Temperature'])
temperature_change['Year'] = temperature_change['Year'].astype(int)
temperature_change = temperature_change[temperature_change['Year'].between(1980, 2020)]
temperature_change = temperature_change.groupby('Year')['Temperature'].mean().reset_index()
temperature_change.rename(columns={'Temperature': 'Temperature Change'}, inplace=True)
temperature_change['Temperature Growth'] = temperature_change['Temperature Change'].diff().fillna(0)
# Merge global temperature change data
global_data = pd.merge(global_data, temperature_change, on='Year')
# Identify top 5 countries with highest population and CO2 emissions
top_countries_population = population_data.groupby('Country')['Population'].sum().nlargest(5).index
top_countries_co2 = co2_emissions.groupby('Country')['CO2 Growth'].sum().nlargest(5).index
top_countries = top_countries_population.union(top_countries_co2)
# Merge population and CO2 data for these countries
country_data = pd.merge(population_data, co2_emissions, on=['Country', 'Year'])
country_data = country_data[country_data['Country'].isin(top_countries)]
# Merge with temperature change data
country_data = pd.merge(country_data, temperature_change, on='Year')
# Create the plot with dropdown menu
fig = px.scatter_3d(global_data, x='Population', y='CO2 Growth', z='Year',
color='Temperature Growth', title='3D Plot of Population, CO2 Growth, and Year with Temperature Change',
color_continuous_scale= px.colors.sequential.Plasma)
# Update layout for better spacing and readability
fig.update_layout(
scene=dict(
xaxis=dict(title='Population (millions)', titlefont=dict(size=14), tickfont=dict(size=12), tickformat='.2s'),
yaxis=dict(title='CO2 Growth', titlefont=dict(size=14), tickfont=dict(size=12)),
zaxis=dict(title='Year', titlefont=dict(size=14), tickfont=dict(size=12))
),
margin=dict(l=0, r=0, b=0, t=40), # Increase margins
title=dict(font=dict(size=20)), # Increase title font size
updatemenus=[dict(
buttons=[
dict(label="World",
method="update",
args=[{"x": [global_data['Population']],
"y": [global_data['CO2 Growth']],
"z": [global_data['Year']],
"marker.color": [global_data['Temperature Growth']]}]
)
] + [
dict(label=country,
method="update",
args=[{"x": [country_data[country_data['Country'] == country]['Population']],
"y": [country_data[country_data['Country'] == country]['CO2 Growth']],
"z": [country_data[country_data['Country'] == country]['Year']],
"marker.color": [country_data[country_data['Country'] == country]['Temperature Growth']]}]
)
for country in top_countries
],
direction="down",
showactive=True
)]
)
fig.show()
/tmp/ipykernel_76121/2394824519.py:47: FutureWarning:
Downcasting object dtype arrays on .fillna, .ffill, .bfill is deprecated and will change in a future version. Call result.infer_objects(copy=False) instead. To opt-in to the future behavior, set `pd.set_option('future.no_silent_downcasting', True)`
In this visualization, you can observe the clear correlation between rising global population numbers and increased CO2 emissions. As the world’s population has grown from around 4.4 billion in 1980 to approximately 7.8 billion in 2020, CO2 emissions have also shown a significant upward trend. This trend underscores the argument that meeting the energy needs of a growing population inherently leads to higher emissions.
While the primary focus here is on global population growth and CO2 emissions, the color gradient indicating temperature differences offers a preliminary look at the broader impact of these emissions on global temperatures. Although the temperature aspect will be explored in more detail later, it is important to note the initial connection visible in the data.
The next section of our analysis will feature a world map that highlights the changes in global temperatures over the same period. By integrating these insights, we aim to provide a comprehensive view of how population dynamics and CO2 emissions contribute to climate change and its tangible effects on our planet.
Rising Temperatures#
Building on the correlation between population growth and CO2 emissions, it is essential to understand how these factors have impacted global temperatures. The next visualization presents a world map depicting the average cumulative temperature changes from 1891 to 2013. This interactive map allows you to slide a bar at the bottom, showing how temperatures have risen significantly in most countries, particularly in the Northern Hemisphere and around major CO2 emitters, over this period:
# TEMP VERHOGING
import pandas as pd
# Parse the 'dt' column to extract the year
df['Year'] = pd.to_datetime(df['dt']).dt.year
# Calculate the average temperature per country per year
avg_temp_per_country_year = df.groupby(['Country', 'Year'])['AverageTemperature'].mean().reset_index()
# Filter the data to only include the time period from 1891 to 2013
filtered_df = avg_temp_per_country_year[(avg_temp_per_country_year['Year'] >= 1891) & (avg_temp_per_country_year['Year'] <= 2013)]
# Determine the min and max average temperatures for the filtered data
min_temp_filtered = filtered_df['AverageTemperature'].min() + 5
max_temp_filtered = filtered_df['AverageTemperature'].max() - 5
print(min_temp_filtered,max_temp_filtered)
import plotly.express as px
# Create a choropleth map using Plotly for the filtered data
fig_filtered = px.choropleth(
filtered_df,
locations="Country",
locationmode="country names",
color="AverageTemperature",
hover_name="Country",
animation_frame="Year",
color_continuous_scale=px.colors.sequential.Plasma,
range_color=(min_temp_filtered, max_temp_filtered),
title="Average Temperature Per Country (1891-2013)"
)
fig_filtered.update_layout(
geo=dict(
showframe=False,
showcoastlines=False,
projection_type='equirectangular'
),
margin={"r":0,"t":0,"l":0,"b":0}
)
# Display the plot
fig_filtered.show()
-15.446833333333334 25.74475
As you interact with the map, you will notice a clear upward trend in average temperatures across the globe. From 1891 to 2013, the average global temperature has increased markedly, with the most pronounced changes occurring in the Northern Hemisphere and around countries with high CO2 emissions such as China, the United States, and India. This region has experienced significant warming, which is consistent with the patterns of industrialization and increased CO2 emissions observed in the earlier visualizations.
The rise in temperatures around major emitters highlights the direct impact of industrial activities on the climate. Since the Industrial Revolution, the world has seen a dramatic increase in CO2 emissions due to the burning of fossil fuels, deforestation, and other industrial processes. This period marks the beginning of a significant upward trend in global temperatures, as reflected in the visualization.
The temperature changes illustrated in this map highlight the tangible effects of increased CO2 emissions and population growth on our planet. These rising temperatures are linked to various climate-related impacts, such as more frequent and severe weather events, melting ice caps, and shifts in ecosystems and biodiversity.
This visualization underscores the urgent need to address the drivers of climate change. By understanding the historical and ongoing changes in global temperatures, we can better appreciate the importance of mitigating CO2 emissions and implementing sustainable practices to protect our environment.
In the following sections, we will explore specific impacts of these temperature changes on different regions and ecosystems. We will also discuss potential strategies and solutions for reducing CO2 emissions and adapting to the changing climate.
Energy Production#
To further understand the relationship between population growth, CO2 emissions, and climate change, it is crucial to examine the trends in global energy production. The following visualization illustrates the increase in energy production from various sources over the past several decades:
# Filter the data to include only the specified countries and exclude "all_energy_types"
selected_countries = ["China", "India", "United States", "Indonesia", "Brazil"]
filtered_energy_data = energy_data[(energy_data['Country'].isin(selected_countries)) &
(energy_data['Energy_type'] != "all_energy_types")]
# Create the interactive bar chart with a year slider for the selected countries and auto-scaling y-axis
fig = px.bar(filtered_energy_data,
x="Country",
y="Energy_production",
color="Energy_type",
animation_frame="Year",
range_y=[0, 150],
title="Energy production by Country and Energy Type Over Time",
labels={"Energy_production": "Energy Production (in PJ)"})
# Show the plot
fig.show()
This visualization shows a clear upward trend in global energy production, reflecting the rising energy demands driven by population growth, industrialization, and economic development. As the world’s population has expanded, so has the need for energy to power homes, industries, and transportation.
The data is broken down by type of energy source, fossil fuels still comprise a significant portion of global energy production, contributing heavily to CO2 emissions.
The correlation between the increase in energy production and CO2 emissions is evident, emphasizing the impact of fossil fuel-based energy on climate change. As energy production has risen, so have CO2 emissions, contributing to the global temperature increases we have observed.
This visualization underscores the urgent need for a transition to cleaner, renewable energy sources to mitigate the impact of climate change. Technological advancements and policy initiatives aimed at increasing the efficiency and output of renewable energy are crucial steps toward reducing global CO2 emissions.
Energy consumption and population growth#
To delve deeper into the relationship between population growth and energy consumption, we present a bubble chart visualization. This chart dynamically illustrates how countries with significant population growth also experience substantial increases in energy consumption over time. The size of the bubbles represents the amount of energy consumed, while the position on the x-axis reflects population growth. By sliding the time slider from 1980 to 2020, you can observe these trends clearly:
# ENerGY CONSUPTION VS POPULATION
country_column = 'Country'
gdp_column = 'GDP'
energy_consumption_column = 'Energy_consumption'
energy_type_column = 'Energy_type' # Adjust to the actual column name in your dataset
population_column = 'Population' # Adjust to the actual column name in your dataset
# Filter out rows with NaN values in 'Population', 'Energy_consumption', and 'GDP' columns
df_energy = df_energy.dropna(subset=[population_column, energy_consumption_column, gdp_column])
# Filter out "World" data
df_energy = df_energy[df_energy['Country'] != 'World']
# Filter for specific energy types that generate CO2 emissions
energy_types = ['coal', 'natural_gas', 'petroleum_n_other_liquids']
df_energy = df_energy[df_energy[energy_type_column].isin(energy_types)]
# Create the scatter plot with animation frame for each year
fig = px.scatter(df_energy, x=population_column, y=energy_consumption_column,
color=energy_type_column,
size=gdp_column,
hover_name=country_column,
log_x=True, # Log scale for x-axis (Population)
log_y=True, # Log scale for y-axis (Energy Consumption)
size_max=60, # Adjust bubble size max limit as needed
animation_frame="Year",
title='Energy Consumption vs Population (1980-2020)',
labels={population_column: 'Population', energy_consumption_column: 'Energy Consumption', energy_type_column: 'Energy Type', gdp_column: 'GDP'}
)
fig.update_layout(
xaxis=dict(title='Population (log scale)'),
yaxis=dict(title='Energy Consumption (log scale)'),
legend_title='Energy Type',
updatemenus=[{
'type': 'buttons',
'showactive': False,
'buttons': [{
'label': 'Play',
'method': 'animate',
'args': [None, {
'frame': {'duration': 1000, 'redraw': True},
'fromcurrent': True,
'transition': {'duration': 500, 'easing': 'quadratic-in-out'}
}]
}, {
'label': 'Pause',
'method': 'animate',
'args': [[None], {
'frame': {'duration': 0, 'redraw': True},
'mode': 'immediate',
'transition': {'duration': 0}
}]
}]
}]
)
fig.show()
Key observations from this visualization include:
Rapid Growth in Developing Nations: Countries with significant population growth, particularly in developing regions, show a corresponding substantial rise in energy consumption. Nations such as China, India, and Brazil are prominent examples where rapid industrialization and urbanization have driven up energy needs.
Steady Increase in Developed Countries: While developed countries like the United States and members of the European Union also show increased energy consumption, the growth rate is less dramatic compared to rapidly developing nations. This is partly due to the already high baseline levels of energy consumption in these countries.
Energy Consumption Patterns: The size of the bubbles indicates the scale of energy consumption, with larger bubbles signifying higher energy use. Countries with both high population growth and significant energy consumption are particularly notable in this chart. As the world’s population continues to grow, the demand for energy will only increase. This trend poses significant challenges for global sustainability and climate change mitigation. The reliance on fossil fuels for energy production has led to rising CO2 emissions, contributing to global warming and climate instability.
In the next section, we will explore the specific impacts of rising energy consumption on CO2 emissions and discuss potential strategies for transitioning to sustainable energy sources. By understanding the interplay between population dynamics and energy use, we can better address the urgent need for sustainable development and climate action.
summary#
sssss